package com.masterclient.app.businessmodule.usermodule.userinfo.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.common.bean.base.CommonBaseBean;
import com.masterclient.app.httpservice.RetrofitUtil;

import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
* Created by TMVPHelper on 2017/08/03
*/
public class UpdateUserPresenter extends UpdateUserContract.Presenter{

    @Override
    public void updateUserInfo(Map<String, String> map) {
        Observable<CommonBaseBean> observable = RetrofitUtil.getInstance().updateUserInfo(map);
        Disposable disposable = toSubscribe(observable, new Consumer<CommonBaseBean>() {
            @Override
            public void accept(@NonNull CommonBaseBean bean) throws Exception {
                if("0".equals(bean.getCode())){
                    mView.updateUserResult(true,"保存成功");
                }else {
                    mView.updateUserResult(false,bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.updateUserResult(false,WEB_FAILED_STR);
            }
        });
        mRxManager.add(disposable);
    }
}